package com.mijie.homi.dao.album;

import java.util.List;
import java.util.HashMap;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.domain.album.Photo;

@Repository
public class PhotoDao extends IBatisDao{

	public int deletePhoto(int userId,long id){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId",userId);
		parameter.put("id",id);
		return this.delete("deletePhoto", parameter);
	}
	
	public int uploadPhoto(List<Photo> list){
		return this.insert("uploadPhoto", list);
	}
	
	public int likePhoto(long id){
		return this.update("likePhoto",id);
	}
	
	public Photo getPhoto(long id){
		return this.selectOne("getPhoto", id);
	}
	
	public List<Photo> listLatestPhoto(int userId,int size){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId",userId);
		parameter.put("size",size);
		return this.selectList("listLatestPhoto", parameter);
	}
	
	public List<Photo> listPhotoByAlbumId(int albumId){
		return this.selectList("listPhotoByAlbumId", albumId);
	}
	
	public List<Photo> listPhotoByUserId(int userId,Long idx,Integer limit){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId",userId);
		if(idx!=null)
			parameter.put("idx",idx);
		if(limit!=null)
			parameter.put("limit",limit);
		return this.selectList("listPhotoByUserId", parameter);
	}
	
	public int increNumOfReview(long id) {
		return this.update("increPhotoNumOfReview", id);
	}

	public int decreNumOfReview(long id) {
		return this.update("decrePhotoNumOfReview", id);
	}
	
}
